<?php
class Webkul_Marketplacepartner_Block_Collection  extends Mage_Core_Block_Template
{
	public function __construct(){
		parent::__construct();
		$cate = Mage::getModel('catalog/category')->load($_GET["id"]);
		$produ = Mage::getModel('catalog/product')->getCollection()->addCategoryFilter($cate)->load();
		$proid=array();
		$j=0;$i=0;
		$mysqlprefix=Mage::getConfig()->getTablePrefix();//code for mysql prefix
		$write = Mage::getSingleton('core/resource')->getConnection('core_write');
		$querydata=$write->query("SELECT mageproductid FROM  ".$mysqlprefix."marketplacepartner_entity_data where userid='".$_GET["id"]."' and mageproductid!='0' ORDER BY  mageproductid");
		$rowdata=$querydata->fetchAll();
		$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('entity_id', array('in' => $rowdata));
		$this->setCollection($collection);	
	}

	protected function _prepareLayout(){
		parent::_prepareLayout();
		$mysqlprefix=Mage::getConfig()->getTablePrefix();//code for mysql prefix
		$write  = Mage::getSingleton('core/resource')->getConnection('core_write');
		$querysocial=$write->query("SELECT compname FROM ".$mysqlprefix."marketplacepartner_entity_userdata where mageuserid='".$_GET["id"]."'");
		$rowsocial=$querysocial->fetch();
		$this->getLayout()->getBlock('head')->setTitle($rowsocial['compname'].'\'s Product Collection');
		$collection = Mage::getModel('catalog/category')->load(1)->getProductCollection();
		$pager = $this->getLayout()->createBlock('page/html_pager', 'custom.pager');
		$pager->setAvailableLimit(array(5=>5,10=>10,20=>20,'all'=>'all'));
		$pager->setCollection($this->getCollection());
		$this->setChild('pager', $pager);
		$this->getCollection($collection);
		return $this;
	}
	public function getDefaultDirection(){
		return 'asc';
	}
	public function getAvailableOrders(){
		return array('name'=> 'Name','position'=>'Position','children_count'=>'Sub Category Count');
	}
	public function getSortBy(){
		return 'name';
	}
	public function getToolbarBlock(){
		$block = $this->getLayout()->createBlock('collection/toolbar', microtime());
		return $block;
	}
	public function getMode(){
		return $this->getChild('toolbar')->getCurrentMode();
	}
	public function getToolbarHtml(){
		return $this->getChildHtml('toolbar');
	}
}